package com.jbl.st.mapper;

import com.jbl.st.entity.CourseclassStudent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jbl
 * @since 2020-12-11
 */
public interface CourseclassStudentMapper extends BaseMapper<CourseclassStudent> {

    @Insert({"INSERT INTO st_courseclass_student ( id, student_id, courseclass_id, state, gmt_create, gmt_modified )\n" +
            "SELECT #{id}, #{studentId}, #{courseclassId}, #{state}, #{gmtCreate}, #{gmtModified}\n" +
            "        FROM DUAL\n" +
            "        WHERE\n" +
            "        (SELECT COUNT(1) FROM st_courseclass_student WHERE courseclass_id = #{courseclassId} AND state = 1) <\n" +
            "        (SELECT limit_number FROM te_courseclass WHERE id = #{courseclassId})"})
    Boolean insertCourseclassStudent(CourseclassStudent courseclassStudent);

}
